/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pe.edu.pucp.dp1.lectura.controlador;

//import pe.edu.pucp.dp1.lectura.modelo.CoordCar;
//import pe.edu.pucp.dp1.lectura.modelo.FileCar;
//import pe.edu.pucp.dp1.lectura.modelo.ObjCar;
import Shared.*;

/**
 *
 * @author Ed
 */
public class HiloUpdateCar extends Thread {

    public GestorCar gestorInstance = GestorCar.getInstance();
    public int iniIntervalHilo;

    public HiloUpdateCar(int limiteIntervalo) {
        setIniIntervalHilo(limiteIntervalo);
    }

    public void run() {
        int seg = 0;
        int saltoHilo = gestorInstance.getIntervalHilo();
        int iniInterval = getIniIntervalHilo();
        int iniSgteInterval = iniInterval + 1;
        int totCars = gestorInstance.getListCarSimu().size();

        while (true) {
            try {
//                System.out.println("Posicion De Carro leida");
                Thread.sleep(1000);
                for (int i = (iniInterval * saltoHilo); (i < (iniSgteInterval * saltoHilo) && (i < totCars)); i++) {
                    //gestorInstance.getFilelistcar().get(i).actualizaRutaActual();//amoldar a semaforos de chokechoke
                    FileCar fileCar = gestorInstance.getFilelistcar().get(i);
                    ObjCar objCar = gestorInstance.getListCarSimu().get(i);
                    if (fileCar != null) {
//                        System.out.println("seg:"+seg+"\t"+carrito.getPlaca()+"\t"+
                        // carrito.getSgtePto(true);
//                        gestorInstance.getListCarSimu().get(i).avanzaPunto(fileCar, gestorInstance.getSemaforos());
                        gestorInstance.avanzaPunto(objCar, fileCar, gestorInstance.getSemaforos());
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            seg++;

        }
    }

    public int getIniIntervalHilo() {
        return iniIntervalHilo;
    }

    public void setIniIntervalHilo(int inicioIntervalHilo) {
        this.iniIntervalHilo = inicioIntervalHilo;
    }
}

